//https://leetcode.cn/problems/wildcard-matching/submissions/585678665/
class Solution {
public:
    bool isMatch(string s, string p) {
        int n = p.size(), m = s.size();
        vector<vector<bool>> dp(n + 1, vector<bool>(m + 1));
        s = ' ' + s;
        p = ' ' + p;
        dp[0][0] = 1;
        for (int i = 1; i <= n; ++i) { if (p[i] != '*')break; else dp[i][0] = true; }
        for (int i = 1; i <= n; ++i)
        {
            for (int j = 1; j <= m; ++j)
            {
                if (p[i] == '*')
                {
                    dp[i][j] = dp[i - 1][j] || dp[i][j - 1];
                }
                else if (p[i] == '?' || p[i] == s[j])
                {
                    dp[i][j] = dp[i - 1][j - 1];
                }
                else dp[i][j] = false;
            }
        }
        return dp[n][m];
    }
};